package me.duyu.tools

import io.vertx.core.Vertx
import io.vertx.ext.web.Router
import io.vertx.ext.web.handler.BodyHandler
import me.duyu.tools.handler.showIndex
import me.duyu.tools.handler.submitInfo
import me.duyu.tools.handler.listClients
import me.duyu.tools.handler.submitInfo2
import me.duyu.tools.handler.listClients2
import me.duyu.tools.handler.infoClient

fun buildRouter(vertx : Vertx) : Router
{
    val router = Router.router(vertx);
    router.route().handler(BodyHandler.create());
    // 在eventloop线程中执行
    router.route("/").handler(::showIndex)

    router.get("/device/list2").handler(::listClients2)
    router.get("/device/list").handler(::listClients)
    router.get("/device/info").handler(::infoClient)
    router.put("/device/info").handler(::submitInfo)
    router.post("/device/info").handler(::submitInfo)
    router.put("/device/info2").handler(::submitInfo2)
    router.post("/device/info2").handler(::submitInfo2)
    // 放到线程池中去执行, 不排队，无序
    //router.route("/block").blockingHandler(::showIndexSync,false)

    return router;
}